package com.atguigu.rabbit.producer.test;

import com.atguigu.rabbit.producer.ProducerApplication;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @Author: Worker Hu
 * @CreateTime: 2024-07-23  15:21
 */
@SpringBootTest(classes = ProducerApplication.class)
public class Producer01 {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    public void testSimple(){
        rabbitTemplate.convertAndSend("simple_queue","hello rabbitmq...");
    }

    @Test
    public void testWork(){
        for (int i = 0; i < 10; i++) {
            rabbitTemplate.convertAndSend("work_queue","工作队列消息"+i);
        }
    }

    @Test
    public void testFanout(){
        for (int i = 0; i < 10; i++) {
            rabbitTemplate.convertAndSend("pubsub_exchange01","","fanout消息"+i);
        }
    }

    @Test
    public void testDirect(){
        rabbitTemplate.convertAndSend("direct_exchange01","error","direct的error消息");
        rabbitTemplate.convertAndSend("direct_exchange01","info","direct消息info信息");
    }

    @Test
    public void testTopic01(){
        rabbitTemplate.convertAndSend("topic_exchange01","1.orange.2","topicQueue01");
        rabbitTemplate.convertAndSend("topic_exchange01","1.2.rabbit","topicQueue02");
    }

    @Test
    public void testTopic02(){
        rabbitTemplate.convertAndSend("topic_exchange02","error","topicQueue01");
        rabbitTemplate.convertAndSend("topic_exchange02","info","topicQueue02");
    }
}


